<template>
  <div class="myCoupon">
    <!-- <x-header :left-options="{backText: ''}">我的优惠券</x-header> -->
    <top :text="'我的优惠券'"></top>
    <div style="height: 46px;"></div>
    <div class="navBar clearfix">
      <ul class="clearfix" style="border-top:1px solid #f6f6f6">
        <li>
          <span :class="{current:status==1}" @click="setStatus(1)">可使用</span>
        </li>
        <li>
          <span :class="{current:status==2}" @click="setStatus(2)">已使用</span>
        </li>
        <li>
          <span :class="{current:status==0}" @click="setStatus(0)">已失效</span>
        </li>
        <!-- <li>
          <span :class="{current:status==3}" @click="setStatus(3)">兑换码</span>
        </li> -->
      </ul>
    </div>

    <div class="available">
      <ul>
        <li :class="{availableCoupon:status==1,useAvaiable:status==2||status==0}" v-for="packet in packetList">
          <div class="availableMoney">
            <span class="symbol">¥</span>
            <span class="money">{{packet.amount}}</span>
          </div>
          <div class="effectiveDate">
            <div>
              {{packet.name}}
              <span class="goUse" @click="useBtn(packet)" v-if="status==1">去使用</span>
            </div>
            <span style=" font-size: 13px;">有效日期:{{packet.started|formatDate}}~{{packet.ended|formatDate}}</span>
          </div>
        </li>
      </ul>
      <div class="invalidCoupon" v-if="packetList.length==0&&status==1">
        <img src="../../assets/noCopon.png" alt="" width="80">
        <div class="c9" style="font-size: 14px">暂无可使用优惠券</div>
      </div>
      <div class="invalidCoupon" v-if="packetList.length==0&&status==2">
        <img src="../../assets/noCopon.png" alt="" width="80">
        <div class="c9" style="font-size: 14px">暂无已使用优惠券</div>
      </div>
      <div class="invalidCoupon" v-if="packetList.length==0&&status==0">
        <img src="../../assets/noCopon.png" alt="" width="80">
        <div class="c9" style="font-size: 14px">暂无已失效优惠券</div>
      </div>
    </div>

    <!--兑换码  -->
    <!-- <div class="available" v-if="status==3">
      <div class="invitation">
        <div style="border-bottom: 1px solid #ccc;width: 50%; margin: auto;padding-bottom: 10px;">
          <div style="padding-top:20px;">请输入优惠券邀请码</div>
          <input type="text" placeholder="不区分大小写" style="border-style:none;outline:none;text-align: center;" class="noBorder">
        </div>
        <span class="confirmBtn" @click="confirmBtn">确认兑换</span>
      </div>
      <div class="rule">
        <p>兑换规则:</p>
        <p>1.兑换成功的优惠券，系统将在2小时内发放到账户中，使用规则及条件在可使用优惠券中查看;</p>
        <p>2.每个邀请码仅可兑换一次;</p>
        <p>3.活动期间遇到问题可联系客服;</p>
      </div>
    </div> -->
  </div>
</template>
<script>
  // import { XHeader } from 'vux'
  import http from '../../service/http.js'
  import tips from '../../service/tips.js'
  import Top from '../../components/common/top.vue'
  export default {
    data() {
      return {
        status: 1,
        packetList: []
      }
    },
    mounted() {
      this.otcType = this.$route.query.otcType;
      this.getPacketList(1)
    },
    methods: {
      useBtn(packet) {
        if (this.$route.query.status == 1) {
          if (packet.name.indexOf('100元') < 0) {
            tips.tips("此优惠券不可以使用");
            return false;
          }
          this.$router.push({ path: "/pay?pid=" + this.$route.query.pid + "&type=" + this.$route.query.type + "&status=1" + "&packetid=" + packet.packetid + "&amount=" + packet.amount })
        } else {
          this.$router.push({ path: "/main/fp/otcList" })
        }
      },
      setStatus(status) {
        this.status = status;
        if (status == 3) {
          this.packetList = [];
          return false;
        }
        this.getPacketList(status);
      },
      getPacketList(status) {
        this.packetList=[];
        http.get("/user/packet?status=" + status, ).then((res) => {
          if (res.data.status == 200) {
            res.data.body.forEach(v => {
              if (v.status == status) {
                this.packetList.push(v);
              }
            });
          }
        }).catch((res) => {
          tips.tips(res.data.msg)
        })
      }
    },
    components: {
      // XHeader,
      Top
    }
  }
</script>
<style lang="less" scoped>
  /* body {
    background: #f6f6f6;
  } */

  .myCoupon {
    position: fixed;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    background: #f6f6f6;
  }

  .myCoupon .vux-header {
    background: #fff;
  }

  .c9 {
    color: #999;
  }

  .myCoupon .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .myCoupon .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .navBar {
    background: #fff;
    ul {
      height: 40px;
      li {
        float: left;
        list-style: none;
        height: 40px;
        line-height: 40px;
        width: 33.33%;
        text-align: center;
        color: #ccc;

      }
    }
    .current {
      color: #ffae33;
      border-bottom: 1px solid #ffae33;
      display: inline-block;
      hight: 40px;
    }
  }

  .available {
    padding: 0px 20px;
    margin-top: 20px;
    ul li {
      list-style: none;
      height: 75px;
      position: relative;
      margin-bottom: 10px;
    }
    .availableMoney {
      height: 75px;
      /* background: red; */
      line-height: 75px;
      color: #fff;
      width: 100px;
      text-align: center;
    }
    .alreadyUsed {
      height: 75px;
      /* background: #f7b0af; */
      line-height: 75px;
      color: #fff;
      width: 100px;
      text-align: center;
    }
    .money {
      font-size: 30px;
      margin-left: -5px;
    }
    .symbol {
      font-size: 20px;
    }
    .effectiveDate {
      position: absolute;
      left: 120px;
      top: 10px;
      min-width: 150px;
      .goUse {
        display: inline-block;
        width: 65px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #ff3838;
        border: 1px solid #ff3838;
        border-radius: 5px;
        position: absolute;
        right: 0px;
      }
    }
  }

  .invalidCoupon {
    text-align: center;
  }

  .invitation {
    text-align: center;
    height: 160px;
    background: #fff;
    border-radius: 15px;
    .noBorder {
      border: none;
      display: block;
      margin: auto;
      margin-top: 15px;
    }
    .confirmBtn {
      width: 200px;
      text-align: center;
      height: 30px;
      line-height: 30px;
      color: #fff;
      background: #ffc337;
      border: 1px solid #ffc337;
      border-radius: 5px;
      display: block;
      margin: auto;
      margin-top: 20px;
    }
  }

  .rule {
    color: #bbb;
    font-size: 15px;
    margin-top: 20px;
  }

  .availableCoupon {
    height: 110px;
    background-image: url('../../assets/couponList.png');
    background-size: 375px;
    border-radius: 10px;
    padding-left: 15px;
    margin-bottom: 10px;
  }

  .useAvaiable {
    height: 110px;
    background-image: url('../../assets/useCoupon.png');
    background-size: 375px;
    border-radius: 10px;
    padding-left: 15px;
    margin-bottom: 10px;
  }
</style>